package org.zy;

import java.util.Map;


public class BooleanExpression implements Calculator<Boolean> {
    private Operator operator;
    private String value;
    private String varName;

    public BooleanExpression(Operator operator, String value, String varName) {
        this.operator = operator;
        this.value = value;
        this.varName = varName;
    }

    public Boolean calculate(Map<String, Object> valueMap) {
        Object value2 = valueMap.get(varName);
        Double v, v2;
        v = Double.valueOf(value2.toString());
        v2 = Double.valueOf(value);
        switch (operator) {
            case EQ:
                return v-v2==0;
            case GE:
                return v - v2 >= 0;
            case GT:
                return v - v2 > 0;
            case LE:
                return v - v2 <= 0;
            case LT:
                return v - v2 < 0;
            default:
                return null;

        }
    }

}
